module.exports = app => {
    return class CartController extends app.Controller {
        async index() {
            let {
                ctx,
                app
            } = this;
            ctx.body = "index";
        }

        async addCart() {
            const res = await this.ctx.service.cart.addCart();
            if (res.code === 0) {
                this.ctx.body = res;
            } else {
                this.ctx.body = {
                    code: 1,
                    msg: res.msg
                }
            }
        } 
        
        async delCart() {
            const res = await this.ctx.service.cart.delCart();
            if (res.code === 0) {
                this.ctx.body = res;
            } else {
                this.ctx.body = {
                    code: 1,
                    msg: res.msg
                }
            }
        }

        async clearCart() {
            const res = await this.ctx.service.cart.clearCart();
            if (res.code === 0) {
                this.ctx.body = res;
            } else {
                this.ctx.body = {
                    code: 1,
                    msg: res.msg
                }
            }
        }

        async cartList() {
            const res = await this.ctx.service.cart.cartList();
             if (res.code === 0) {
                this.ctx.body = res;
            } else {
                this.ctx.body = {
                    code: 1,
                    msg: res.msg
                }
            }
        }
    }
}
